package com.szqhyxj.youxiangju.biz.merchantHome.shop;

import com.szqhyxj.youxiangju.biz.merchantHome.bean.CommoditeDetails;
import com.szqhyxj.youxiangju.biz.merchantHome.bean.PosCommodity;
import com.szqhyxj.youxiangju.biz.merchantHome.shop.purchase.PreparePurchaseEntity;
import com.szqhyxj.youxiangju.sys.BaseResult;
import com.szqhyxj.youxiangju.sys.RetrofitFacade;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

/**
 * XiaoPanYu
 * on 2018/10/31
 */
public class ShopModel{

    public interface ShopService {


        @POST("posPackage/query")
        Observable<BaseResult<List<PosCommodity>>> queryCommodity();

        @FormUrlEncoded
        @POST("order/pay/pos/inventory")
        Observable<BaseResult<String>> getPosiNventory( @Field("packageId") String packageId);

        @FormUrlEncoded
        @POST("posPackage/getPosPackage")
        Observable<BaseResult<CommoditeDetails>> getPosPackage(@Field("packageId") String packageId);


        @FormUrlEncoded
        @POST("order/pay/pos/place")
        Observable<BaseResult<String>> placeOrder( @Field("address") String address,
                                                             @Field("byType") String byType,
                                                             @Field("packageId") String packageId,
                                                             @Field("payType") String payType);

        @FormUrlEncoded
        @POST("goods/detail")
        Observable<BaseResult<PreparePurchaseEntity>> goodsDetail (@Field("id") String id);

    }

    public static Observable<BaseResult<List<PosCommodity>>> queryCommodity () {
        return RetrofitFacade.Companion.getRetrofit().create(ShopService.class).queryCommodity();
    }

    public static Observable<BaseResult<CommoditeDetails>> getPosPackage (String packageId) {
        return RetrofitFacade.Companion.getRetrofit().create(ShopService.class).getPosPackage(packageId);
    }

    //获取上级库存
    public static Observable<BaseResult<String>> getPosiNventory (String packageId) {
        return RetrofitFacade.Companion.getRetrofit().create(ShopService.class).getPosiNventory(packageId);
    }

    public static Observable<BaseResult<String>> placeOrder (OrderEntity orderEntity) {
        return RetrofitFacade.Companion.getRetrofit().create(ShopService.class).placeOrder(orderEntity.getAddress()
                ,orderEntity.getByType()
                ,orderEntity.getPackageId()
                ,orderEntity.getPayType());
    }

    public static Observable<BaseResult<PreparePurchaseEntity>> getGoodsDetail(String id){
        return RetrofitFacade.Companion.getMockretrofit().create(ShopService.class).goodsDetail(id);
    }


    public static class OrderEntity{

        public static final String platform = "2";
        public static final String superior = "1";
        /**
         * address : 5567
         * byType : 1
         * packageId : 4
         * payType : 网页支付传alipayH5，app支付传alipayApp
         */

        private String address;
        private String byType = ShopModel.OrderEntity.platform;
        private String packageId;
        private String payType;

        public String getAddress(){
            return address;
        }

        public void setAddress(String address){
            this.address = address;
        }

        public String getByType(){
            return byType;
        }

        public void setByType(String byType){
            this.byType = byType;
        }

        public String getPackageId(){
            return packageId;
        }

        public void setPackageId(String packageId){
            this.packageId = packageId;
        }

        public String getPayType(){
            return payType;
        }

        public void setPayType(String payType){
            this.payType = payType;
        }
    }
}
